package P09_ThreadPool线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class P01_ThreadPoolDemo1 {
    public static void main(String[] args) {
        // 一池五线程
//        ExecutorService pool1 = Executors.newFixedThreadPool(5); // 快

        // 一池一线程
//        ExecutorService pool1 = Executors.newSingleThreadExecutor(); // 慢

        // 一池可扩容线程
        ExecutorService pool1 = Executors.newCachedThreadPool(); // 快
        // 10个顾客请求
        try {
            for (int i = 0; i < 20; i++) {
                pool1.execute(() ->{
                    System.out.println(Thread.currentThread().getName() + "办理业务");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                });
            }
        } finally {
            pool1.shutdown();
        }
    }
}
